import { User, KnowledgeBase, Document, Chat, Message } from "@prisma/client";

/**
 * API响应类型
 */
export type ApiResponse<T> = {
  success: boolean;
  data?: T;
  error?: string;
  status?: number;
};

/**
 * 带文档的知识库
 */
export type KnowledgeBaseWithDocuments = KnowledgeBase & {
  documents: Document[];
};

/**
 * 带消息的聊天
 */
export type ChatWithMessages = Chat & {
  messages: Message[];
};

/**
 * 创建知识库请求
 */
export type CreateKnowledgeBaseRequest = {
  name: string;
  description?: string;
};

/**
 * 上传文档请求
 */
export type UploadDocumentRequest = {
  knowledgeBaseId: string;
  file: File;
};

/**
 * 创建聊天请求
 */
export type CreateChatRequest = {
  knowledgeBaseId: string;
  title?: string;
};

/**
 * 创建消息请求
 */
export type CreateMessageRequest = {
  chatId: string;
  content: string;
  role: "user" | "assistant";
};

/**
 * 聊天完成请求
 */
export type ChatCompletionRequest = {
  chatId: string;
  message: string;
};

/**
 * 流式响应事件类型
 */
export enum StreamResponseEventType {
  Start = "start",
  Token = "token",
  End = "end",
  Error = "error",
}

/**
 * 流式响应事件
 */
export type StreamResponseEvent =
  | {
      type: StreamResponseEventType.Start;
      messageId: string;
    }
  | {
      type: StreamResponseEventType.Token;
      token: string;
    }
  | {
      type: StreamResponseEventType.End;
    }
  | {
      type: StreamResponseEventType.Error;
      error: string;
    };

/**
 * 模型设置
 */
export type ModelSettings = {
  temperature: number;
  top_p: number;
  top_k: number;
  max_tokens: number;
};

/**
 * 获取聊天请求的参数
 */
export type GetChatParams = {
  knowledgeBaseId: string;
  chatId: string;
};

/**
 * 分页请求
 */
export type PaginationRequest = {
  page: number;
  pageSize: number;
};

/**
 * 分页响应
 */
export type PaginatedResponse<T> = {
  items: T[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
};

/**
 * 用户信息包含知识库
 */
export type UserWithKnowledgeBases = User & {
  knowledgeBases: KnowledgeBase[];
}; 